import { CommonQueryParams, POST, Auth, QueryParams, ResponeList, PUT, GET, OptRespone } from 'spd-request';
export interface IEnterpriseStruct {
    code: string;
    creationTime: string;
    creationUniversalTime: number;
    creatorUserId: number;
    description: string;
    displayName: string;
    id: number;
    lastModificationTime: string;
    lastModificationUniversalTime: 1610358416
    lastModifierUserId: number;
    level: number;
    memberCount: number;
    parentId: null
    parentName: null
    primaryId: string;
    sort: number;
}
export interface IAddDepartmentData {
    description?: string;
    displayName: string;
    enterpriseId?: string;
    level?: number
    parentId?: number
    sort?: number;
    id?: number;
}
export namespace OriganizationUnit {
    
    export function getEnterpriseOrganizationUnits(params: {id: string} = {id:'00000000-0000-0000-0000-000000000000'}): Promise<OptRespone<ResponeList<IEnterpriseStruct>>> {
        return GET('/OrganizationUnit/GetEnterpriseOrganizationUnits', {params: {enterpriseId: params.id}}).then(res => {
            if(res.success === true) {
                return {error: null, data: res.result};
            } else {
                return {error: '获取企业列表数据失败！', data: {totalCount: 0, items: []}};
            }
        }).catch(() => {
            return {error: '获取企业列表数据失败！', data: {totalCount: 0, items: []}}
        });
    }

    export function createOrUpdateOrganizationUnitExtend(params: IAddDepartmentData): Promise<{error: null, data: IEnterpriseStruct}|{error: string, data: null}> {
        if(params.id !== undefined || params.id != null) {
            return PUT('/OrganizationUnit/CreateOrganizationUnitExtend', params).then(res => {
                if(res.success == true) {
                    return {error: null, data: res.result};
                } else {
                    return {error: '添加失败', data: null}
                }
            });
        } else {
            return POST('/OrganizationUnit/CreateOrganizationUnitExtend', params).then(res => {
                if(res.success == true) {
                    return {error: null, data: res.result};
                } else {
                    return {error: '添加失败', data: null}
                }
            });
        }
    }
}